package Test28;

//自幂数，一个n位自然数等于自身各个数位上数字的n次幂之和

public class Test03 {
    public static void main(String[] args) {
        //水仙花数
        int count3 = 0;
        for (int i = 100; i <= 999; i++) {
            int ge = i % 10;
            int shi = i / 10 % 10;
            int bai = i / 10 / 10 % 10;
            double sum = Math.pow(ge, 3) + Math.pow(shi, 3) + Math.pow(bai, 3);
            if (sum == i) {
                System.out.println(i);
                count3++;
            }
        }
        System.out.println("一共有" + count3 + "个水仙花数");

        System.out.println("---------------");

        //四叶玫瑰数
        int count4 = 0;
        for (int i = 1000; i <= 9999; i++) {
            int ge = i % 10;
            int shi = i / 10 % 10;
            int bai = i / 10 / 10 % 10;
            int qian = i / 10 / 10 / 10 % 10;
            double sum = Math.pow(ge, 4) + Math.pow(shi, 4) + Math.pow(bai, 4) + Math.pow(qian, 4);
            if (sum == i) {
                System.out.println(i);
                count4++;
            }
        }
        System.out.println("一共有" + count4 + "个四叶玫瑰数");

        System.out.println("---------------");

        //五角星数
        int count5 = 0;
        for (int i = 10000; i <= 99999; i++) {
            int ge = i % 10;
            int shi = i / 10 % 10;
            int bai = i / 10 / 10 % 10;
            int qian = i / 10 / 10 / 10 % 10;
            int wan = i / 10 / 10 / 10 / 10 % 10;
            double sum = Math.pow(ge, 5) + Math.pow(shi, 5) + Math.pow(bai, 5) + Math.pow(qian, 5) + Math.pow(wan, 5);
            if (sum == i) {
                System.out.println(i);
                count5++;
            }
        }
        System.out.println("一共有" + count5 + "个四叶玫瑰数");

        System.out.println("---------------");

        //为什么没有两位的自幂数？
        int count2 = 0;
        for (int i = 10; i <= 99; i++) {
            int ge = i % 10;
            int shi = i / 10 % 10;
            double sum = Math.pow(ge, 2) + Math.pow(shi, 2);
            if (sum == i) {
                System.out.println(i);
                count2++;
            }
        }
        System.out.println("一共有" + count2 + "个两位的自幂数");
    }
}
